package models.order;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import com.fbpost.util.StringUtil;

import play.db.jpa.Model;

/**
 * 订单收件人信息
 * 
 * @author yechao
 * @date 2013年11月3日
 */
@Entity
@Table(name = "order_receiver")
public class OrderReceiver extends Model {
	/**
	 * 订单ID, 订单表的ID
	 */
	@Column(name = "order_id")
	public Long orderId;
	/**
	 * 收件人名
	 */
	@Column(name = "receiver_name")
	public String receiverName;

	/**
	 * 街道1
	 */
	@Column(name = "address_line1")
	public String addressLine1;

	/**
	 * 街道2
	 */
	@Column(name = "address_line2")
	public String addressLine2;

	/**
	 * 省/州
	 */
	@Column(name = "state")
	public String state;

	/**
	 * 城市
	 */
	@Column(name = "city")
	public String city;
	/**
	 * 邮编
	 */
	@Column(name = "zip")
	public String zip;

	/**
	 * 国家,此处本应设计为 国家库表的id
	 * 
	 * 但为了防止出现 国家库无该国家名称,编码不一致,或者其他原因无法在国家库找到记录,导致订单无法发货
	 * 
	 * 所以这里直接保存 国家2字码和国家英文名称
	 */
	@Column(name = "country_code")
	public String countryCode;

	/**
	 * 国家名称, 不限制语言
	 */
	@Column(name = "country_name")
	public String countryName;

	/**
	 * 收件人电话号码
	 */
	@Column(name = "phone_number")
	public String phoneNumber;
	/**
	 * 收件人邮箱
	 */
	@Column(name = "email")
	public String email;

	/**
	 * 获取完整的英文地址
	 * 
	 * @return
	 */
	public String getFullAddress() {
		String fullAddress = "";

		if (!StringUtil.isNull(this.receiverName)) {
			fullAddress = this.receiverName + "\n";
		}

		if (!StringUtil.isNull(this.addressLine1)) {
			fullAddress += this.addressLine1 + "\n";
		}

		if (!StringUtil.isNull(this.addressLine2)) {
			fullAddress += this.addressLine2 + "\n";
		}

		if (!StringUtil.isNull(this.city)) {
			fullAddress += this.city + "\n";
		}

		if (!StringUtil.isNull(this.state)) {
			fullAddress += this.state;
		}

		if (!StringUtil.isNull(this.zip)) {
			fullAddress += (" " + this.zip);
		}

		if (!StringUtil.isNull(this.countryName)) {
			// 国家单独最后一行
			fullAddress += "\n" + this.countryName;
		}
		return fullAddress;
	}
}
